/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1603.tata.util;

import edu.fjut.se1603.tata.util.ConnectMySQL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author admin
 */
public class PetOwnerService {
    public static int login()
    {
         ConnectMySQL s=new  ConnectMySQL();
          java.sql.Connection conn=s.Connect();
          int biaoshi=0;
         try {
             //提示用户输入密码
             Scanner input=new Scanner(System.in); 
            /* System.out.print("请输入登陆模式，输入1为宠物主人登陆，输入2为宠物商店登陆:");
             int pd = input.nextInt();
             while(pd!=1&&pd!=2)
             {
                 System.out.println("登陆模式错误！");
                 System.out.print("请输入登陆模式，输入1为宠物主人登陆，输入2为宠物商店登陆:");
                 pd = input.nextInt();
             }*/
             System.out.print("请输入用户名：");
             String name = input.next();
             
             System.out.print("请输入登陆密码：");
             String password = input.next();
             //对表进行查询
             PreparedStatement pst;
              pst=conn.prepareStatement("select * from petowner where NAME=? and PASSWORD=?");

            pst.setString(1, name);
            pst.setString(2, password);
            ResultSet rs = pst.executeQuery();
             if (rs.next()) {
                 System.out.println("——————恭喜你登陆成功—————");
                 System.out.println("名字："+rs.getString("NAME"));
                 System.out.println("元宝数："+rs.getString("MONEY"));
                 biaoshi=rs.getInt("ID");
             } else {
                 System.out.println("登陆失败！");
                biaoshi=0;
             }
         } catch (SQLException ex) {
            Logger.getLogger(Log_in.class.getName()).log(Level.SEVERE, null, ex);
        }    finally{
        //关闭连接
       s.conclose();
      }
         return biaoshi;
    }
    
}
